<?php
namespace App\Http\Controllers\Api\Buz;

use App\Http\Controllers\Controller;
use App\Repositories\Criteria\AuthUserCriteria;
use App\Repositories\Criteria\MchNoCriteria;
use App\Repositories\Criteria\OrderStatusCriteria;
use App\Repositories\Criteria\TimeFilterCriteria;
use App\Repositories\Eloquent\FinanceBillRepository;
use App\Services\ApiResponseService;
use Illuminate\Http\Request;

class FinanceBillController extends Controller
{
    protected $billRepo;

    public function __construct(FinanceBillRepository $billRepository)
    {
        $this->billRepo = $billRepository;
        $this->billRepo->pushCriteria(new AuthUserCriteria('bill_uid'));
    }

    public function index(Request $request)
    {
        $billType = $request->input('billType') ? : 99;
        $channel_id = $request->input('orderNo') ?? '';
        $pageSize = $request->input('pageSize') ?? 20;
        $this->billRepo->pushCriteria(new TimeFilterCriteria($request, 'created_at', false));
        $this->billRepo->pushCriteria(new OrderStatusCriteria($billType, 'bill_type'));
        $this->billRepo->pushCriteria(new MchNoCriteria($channel_id, 'channel_id'));
        $bills = $this->billRepo
            ->orderBy('created_at', 'desc')
            ->paginate($pageSize, ['bill_id', 'channel_id', 'bill_type', 'bill_channel', 'bill_amt', 'cur_available', 'created_at', 'bill_info']);
        return ApiResponseService::returnData($bills);


    }
}
